package com.cskaoyan.market.service.impl;

import com.cskaoyan.market.db.domain.MarketLog;
import com.cskaoyan.market.db.domain.MarketLogExample;
import com.cskaoyan.market.db.mapper.MarketLogMapper;
import com.cskaoyan.market.service.MarketLogService;
import com.cskaoyan.market.util.MyBatisUtil;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * ClassName: MarketLogServiceImpl
 * Package: com.cskaoyan.market.service.impl
 * Date: 2023/5/8 - 14:15
 * Description:
 */
public class MarketLogServiceImpl implements MarketLogService {
    @Override
    public List<MarketLog> list(String page, String limit, String sort, String order, String userName) {
        SqlSession sqlSession = MyBatisUtil.getSession();
        MarketLogMapper marketLogMapper = sqlSession.getMapper(MarketLogMapper.class);
        MarketLogExample marketLogExample = new MarketLogExample();
        List<MarketLog> marketLogs = null;
        Integer pageInteger = Integer.valueOf(page);
        Integer limitInteger = Integer.valueOf(limit);
        marketLogExample.orderBy(sort + " " + order);
        MarketLogExample.Criteria or = marketLogExample.or();
        or.andDeletedEqualTo(false);
        System.out.println(userName + "========================");
        if (!StringUtils.isEmpty(userName)) {
            or.andAdminLike("%" + userName + "%");
        }
        PageHelper.startPage(pageInteger, limitInteger);
        marketLogs = marketLogMapper.selectByExample(marketLogExample);
        sqlSession.commit();
        sqlSession.close();
        if (marketLogs.size() == 0) {
            return null;
        }
        return marketLogs;
    }
}
